{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6950a5a1",
   "metadata": {},
   "source": [
    "* 日期：2022.10.12\n",
    "* 课程：python\n",
    "* 记录人：zhanghao"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40aca5e3",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 有序的数据结构-字符串\n",
    ">> 1. 字符串的基本概念（回顾）\n",
    ">>> 1. ‘’\n",
    ">>> 2. “”\n",
    ">>> 3. “““”””\n",
    ">> 2. 字符串的性质和方法\n",
    "> 2. 有序的数据结构—列表\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dcd6496b",
   "metadata": {},
   "source": [
    "# 1.字符串的性质和方法\n",
    "\n",
    "* 字符串的性质\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    "> 3. 使用len()检查字符串的长度\n",
    "* 字符串的基础方法\n",
    "> 1. 字符串的取值 :str[index]\n",
    "> 2. 字符串的切片：str[start,stop],stop取不到\n",
    "> 3. 字符串的拼接：+\n",
    "> 4. in 检查成员是否存在\n",
    "* 字符串的一般方法（function/Methods 函数/方法）\n",
    "> 1. isdigit()\n",
    ">> 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c3aab369",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "509c2624",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]\n",
    "//0是索引值 index  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a8997cf8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0d86b7a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2bc949af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0] + text[1] + text[2] + text[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b7c6b446",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6] # 等价于[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8e411da8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "cf986975",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a26b2d3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b4c4a907",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2018767979.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [13]\u001b[1;36m\u001b[0m\n\u001b[1;33m    *\u001b[0m\n\u001b[1;37m      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "* in 检查成员对象\n",
    "* conunt() 检查字符串出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cd9e09f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "cd76a835",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "2084e4fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "803eee43",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "04a53e01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用Int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "   print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c82101e",
   "metadata": {},
   "source": [
    "##  2. 有序的数据结构—列表（List）\n",
    "* 列表的概念和基本性质\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27ffb112",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符进行操作。列表式对item进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "1e03cab0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1,4,9,16,25] # 列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "e6226a64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] # 列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "96acbf6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"Jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "fa0f811b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "d480b3b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*squares "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0f6c6447",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Marry']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "f617cff2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Marry']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出\"Jack\",\"Marry\" 用切片的方法\n",
    "names[:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99cc39ac",
   "metadata": {},
   "source": [
    "* 列表的一般方法（如何学习）\n",
    "> 1. 增加\n",
    "> 2. 删除\n",
    "> 3. 改\n",
    "> 4. 查：in\n",
    "*列表的学习方法(步骤)\n",
    "> 1. 使用 Tab 键查看列表的方法\n",
    "> 2. 使用help(查看方法的使用规则)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70316153",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后作业\n",
    "* 列表的方法尝试所有的方法\n",
    "* 总结列表的方法学习心得（表格形式总结）\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
